home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 476-500 / disk_497 / nlcalc / source / chandler.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  3KB  |  102 lines

  1. /*
  2.  *  CALC      Provides a calculator that opens on the active screen when
  3.  *            you press a specific key sequence.  Otherwise, the program
  4.  *            waits quitely in the background.
  5.  *
  6.  *              Copyright 1989 by Davide P. Cervone.
  7.  *  You may use this code, provided this copyright notice is kept intact.
  8.  */
  9.  
  10. #define INTUITION_PREFERENCES_H         /* don't need 'em */
  11. #include <intuition/intuitionbase.h>
  12. #include <devices/input.h>
  13. #include <libraries/dos.h>
  14. #include <proto/exec.h>
  15. #include <proto/dos.h>
  16.  
  17. #include "cHandler.h"
  18. #include "cSetup.h"
  19.  
  20. #ifndef SWINDOWS
  21. #define CLOSEDELAY      5
  22. static APTR CloseTask;          /* The task that asked to close the window
  23.                                    were the calculator is currently open */
  24. #endif
  25.  
  26. UWORD KeyCode;                  /* The keycode to activate the calculator */
  27. UWORD Qualifiers;               /*   and required qualifiers */
  28.  
  29.  
  30. /*
  31.  *  myHandler()
  32.  *
  33.  *  The input handler that looks for the keypress that brings up the
  34.  *  calculator.  It scans the input event list for RAWKEY events that
  35.  *  match the given keycode.  If the qualifiers match, and the active 
  36.  *  screen is not the one containing the calculator (or the calculator
  37.  *  is not open) then signal the calc task to open the calculator on 
  38.  *  the active screen and removes the event from the EventList.
  39.  */
  40.  
  41. struct InputEvent *myHandler(EventList,data)
  42. struct InputEvent *EventList;
  43. APTR data;
  44. {
  45.    struct InputEvent **EventPtr = &EventList;
  46.    struct InputEvent *theEvent;
  47.    
  48.    while ((theEvent = *EventPtr) != NULL)
  49.    {
  50.       if (theEvent->ie_Class == IECLASS_RAWKEY &&
  51.           theEvent->ie_Code  == KeyCode &&
  52.          (theEvent->ie_Qualifier & Qualifiers) == Qualifiers &&
  53.           IntuitionBase->ActiveScreen != CalcScreen)
  54.       {
  55.          Signal(CalcTask,CalcSMask);
  56.          *EventPtr =   theEvent->ie_NextEvent;
  57.       } else {
  58.           EventPtr = &(theEvent->ie_NextEvent);
  59.       }
  60.    }
  61.    return(EventList);
  62. }
  63.  
  64.  
  65. /*
  66.  *  cCloseScreen()
  67.  *
  68.  *  Our replacement CloseScreen routine, called before the real CloseScreen.
  69.  *  If the screen is the one containing the calculator and the calculator
  70.  *  is open, and there is not already a task waiting to be signaled, then 
  71.  *  get the current task pointer, and clear the CLOSESIGNAL.  Signal the
  72.  *  calculator to close since the screen is about to close.  Wait for
  73.  *  the CalcTask to signal us that the calculator is closed.  Now it is
  74.  *  safe to close the screen.
  75.  */
  76.  
  77. #ifndef SWINDOWS
  78. void cCloseScreen(theScreen)
  79. struct Screen *theScreen;
  80. {
  81.    extern APTR FindTask();
  82.  
  83.    if (theScreen == CalcScreen && CalcWindow && CloseTask == NULL)
  84.    {
  85.       CloseTask = FindTask(NULL);
  86.       SetSignal(0L,CLOSESIGNAL);
  87.       Signal(CalcTask,CalcCMask);
  88.       Wait(CLOSESIGNAL);
  89.       CloseTask = NULL;
  90.    }
  91. }
  92.  
  93. void SignalClosed()
  94. {
  95.    if (CloseTask)
  96.    {
  97.       Delay(CLOSEDELAY);
  98.       Signal(CloseTask,CLOSESIGNAL);
  99.    }
  100. }
  101. #endif
  102.